/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
 */
package BD;

import Tools.Datos;
import java.sql.*;

/**
 * 
 * @author ARMGARCES
 */
public class Bd {
    protected String[] params;
    protected Connection connection;
    
    /***************************************************************************/
    /********************************** BD *************************************/
    /***************************************************************************/
    /**
     * 
     */
    public Bd(){
       
    }
    /**
     * 
     * @return 
     */
    public Connection open(){
        return null;
    } 
    /***************************************************************************/
    /******************************** AUDIT ************************************/
    /***************************************************************************/
    /**
     * 
     * @param username
     * @param pkValue
     * @param mensaje
     * @throws SQLException 
     */
    public void auditar(String username,String pkValue,String mensaje) throws SQLException{
        StringBuilder sqlAud = new StringBuilder();
        sqlAud.append("{call sp_upd_user_audit(?,?,?,?,?,?,?,?)}");
        CallableStatement cstmt1 = connection.prepareCall(sqlAud.toString());                           
        cstmt1.setString("@audit_tb", "tb_audit_bd");
        cstmt1.setString("@audit_pk", "id_aud_bd");
        cstmt1.setString("@pk_value", pkValue);
        cstmt1.setString("@id_user", username);
        String[] host = Datos.getLocalHost();
        cstmt1.setString("@ip_terminal", host[0]);
        cstmt1.setString("@ip_direccion",host[1]);
        cstmt1.setString("@ip_mac", host[2]);
        cstmt1.setString("@mensaje", mensaje);
        cstmt1.execute();
    }        
    /***************************************************************************/
    /******************************* SINGLETON *********************************/
    /***************************************************************************/
    
    private static class BdHolder {
        private static final Bd INSTANCE = new Bd();
    }
    
    public static Bd getInstance() {
        return Bd.BdHolder.INSTANCE;
    }
    
}

